package com.KA.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket(Environment environment) {
        //设置要显示的swagger环境
        Profiles profiles = Profiles.of("dev");
        //判断自己是否处于设定的环境中
        boolean flag = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).groupName("daodao");
        //通过flag判断该环境是否能访问swagger
        //.enable(flag)
        //.select()
        //any():扫描全部
        //none():都不扫描
        //basePackage():扫描指定的包
        //withClassAnnotation():扫描类上的注解，参数是注解的反射对象（restController）
        //withMethodAnnotation：扫描方法上的注解
//                .apis(RequestHandlerSelectors.withMethodAnnotation(GetMapping.class))
//                //过滤什么路径
//                .paths(PathSelectors.ant("/daodao/**"))
//                .build();
    }

    public ApiInfo apiInfo() {
        Contact contact = new Contact("刀刀","localhost:8080","123455@qq.com");
        return new ApiInfo("刀刀",
                "即使再小的帆也能远航",
                "1.0",
                "localhost:8080",
                contact,
                "apache2.0",
                "wangjiansuoyou",
                new ArrayList<>());
    }
}
